package welsch.androidwerwolf;

import android.media.Image;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;

/**
 * Created by loki on 10.01.2015.
 */
public class Player implements Serializable{
    private String cName = "";
    private transient  Image cImage = null;
    private transient  boolean cIsDead = false;
    public Player(String name){
        cName = name;
    }

    public Player(String name,Image image){
        cName = name;
        cImage = image;
    }

    public void setName(String name){
        cName = name;
    }
    public String getName(){
        return cName;
    }
    public Image getImage(){
        return  cImage;
    }


    public void setIsDead(boolean value){
        cIsDead = value;
    }

    public  boolean isDead(){
        return this.cIsDead;
    }

    public static  Player load(String path){
        Player result = null;
        try
        {
            FileInputStream fileIn = new FileInputStream("/tmp/employee.ser");
            ObjectInputStream in = new ObjectInputStream(fileIn);
            result = (Player) in.readObject();
            in.close();
            fileIn.close();

        }catch(IOException i)
        {
            i.printStackTrace();

        }catch(ClassNotFoundException c)
        {
            System.out.println("Employee class not found");
            c.printStackTrace();

        }

        return result;
    }

    public void save() {
        ObjectOutputStream out = null;
        FileOutputStream fileOut = null;
        try
        {
            fileOut =new FileOutputStream("");
            out = new ObjectOutputStream(fileOut);

        }catch(IOException i)
        {
            i.printStackTrace();
        }
        finally {

            try {

                if(out !=null)out.close();
                if(fileOut != null)fileOut.close();

            } catch (IOException e) {
                e.printStackTrace();
            }

        }

    }
}
